'use strict';
// npx sequelize migration:generate --name=<操作名称></操作名称>
// npx sequelize db:migrate
// npx sequelize db:migrate:undo

module.exports = {
  up: async (queryInterface, Sequelize) => {
    const { INTEGER, DATE, STRING, BOOLEAN, DECIMAL } = Sequelize;
    await queryInterface.createTable('loading', {
      id: { type: INTEGER, primaryKey: true, autoIncrement: true },
      carno: { type: STRING(30), comment: '车牌号' },
      checkno: { type: STRING(30), comment: '核放单号' },
      WareHouseBillCode: { type: STRING(30), comment: '报关申请单号', field: 'WareHouseBillCode' },
      loadType: { type: STRING(1), comment: '装/卸货类型 I：装货 E：卸货', field: 'loadType' },
      loadTime: { type: DATE, comment: '装卸货时间', field: 'loadTime' },
      store_id: { type: INTEGER, comment: '仓库' },
      corp_id: { type: INTEGER, comment: '仓库使用公司' },
      owner: { type: STRING(30), comment: '创建者' },
      swner: { type: STRING(30), comment: '审核者' },
      sdate: DATE,
      description: STRING(200),
      status: STRING(10),
      created_at: DATE,
      updated_at: DATE,
    });

    await queryInterface.createTable('instore', {
      id: { type: INTEGER, primaryKey: true, autoIncrement: true },
      billNo: { type: STRING(30), unique: true, field: 'billNo' },
      goods_id: { type: STRING(36), unique: true },
      store_id: { type: INTEGER },
      loading_id: { type: INTEGER, comment: '车辆装卸记录' },
      // carno: { type: STRING(30), comment: '车牌号' },
      // checkno: { type: STRING(30), comment: '核放单号' },
      // WareHouseBillCode: { type: STRING(30), comment: '报关申请单号', field: 'WareHouseBillCode' },
      corp_id: { type: INTEGER, comment: '仓库使用公司' },
      owner: { type: STRING(30), comment: '创建者' },
      swner: { type: STRING(30), comment: '审核者' },
      sdate: DATE,

      description: STRING(200),
      status: STRING(10),
      created_at: DATE,
      updated_at: DATE,
    });

    await queryInterface.createTable('outstore', {
      id: { type: INTEGER, primaryKey: true, autoIncrement: true },
      billNo: { type: STRING(30), unique: true, field: 'billNo' },
      goods_id: { type: STRING(36), unique: true },
      store_id: { type: INTEGER },
      loading_id: { type: INTEGER, comment: '车辆装卸记录' },
      corp_id: { type: INTEGER, comment: '仓库使用公司' },
      owner: { type: STRING(30), comment: '创建者' },
      swner: { type: STRING(30), comment: '审核者' },
      sdate: DATE,

      description: STRING(200),
      status: STRING(10),
      created_at: DATE,
      updated_at: DATE,
    });

    await queryInterface.createTable('store_batch', {
      id: { type: INTEGER, primaryKey: true, autoIncrement: true },
      batch: { type: STRING(30), comment: '批次号' },
      goods_id: { type: STRING(36) },
      number: { type: INTEGER, comment: '每日序号' },
      ymd: { type: STRING(10), comment: '年-月-日' },
      corp_id: { type: INTEGER },
      description: STRING(200),
      created_at: DATE,
      updated_at: DATE,
    });

    await queryInterface.createTable('store_good', {
      id: { type: INTEGER, primaryKey: true, autoIncrement: true },
      stype: { type: STRING(1), comment: '入库或出库' },
      goods_id: { type: STRING(36) },
      sku: { type: STRING(255), comment: '商品SKU' },
      materialsCode: { type: STRING(255), comment: '商品料件号', field: 'materialsCode' },
      place: { type: STRING(50), comment: '库位' },
      batch: { type: STRING(30), comment: '批号' },
      count: { type: DECIMAL(11, 2), comment: '申报数量' },
      unit: { type: STRING(30), comment: '申报单位' },
      price: { type: DECIMAL(16, 2), comment: '申报价格' },
      currency: STRING(10),
      description: STRING(200),
      status: STRING(10),
      created_at: DATE,
      updated_at: DATE,
    });
  },

  down: async queryInterface => {
    await queryInterface.dropTable('loading');
    await queryInterface.dropTable('store_good');
    await queryInterface.dropTable('store_batch');
    await queryInterface.dropTable('outstore');
    await queryInterface.dropTable('instore');
  },
};
